package com.lynx.core.impl;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lynx.core.View;
import com.lynx.core.type.Encoding;
/**
 * 
 * @author lxp
 *
 */
public class HtmlView implements View {

	private  String ENCODING = Encoding.utf_8.getCode();
	private final String text;

	public HtmlView(String text) {
		this.text = text;
	}
	public HtmlView(String text,Encoding encoding) {
		this.text = text;
		this.ENCODING = encoding.getCode();
	}

	public void render(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException,Exception {
		response.setCharacterEncoding(ENCODING);
		response.setHeader("Content-Type", "text/html; charset=" + ENCODING);
		PrintWriter writer = response.getWriter();
		try {
			writer.print(this.text);
		} finally {
			writer.close();
		}
	}

}
